<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible">
    <meta name="viewport" content="width=device-width" , initial-scale="1">
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdn.bootcss.com/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
测试界面
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">×
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    模态框（Modal）标题
                </h4>
            </div>
            <div class="modal-body">
                按下 ESC 按钮退出。
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default"
                        data-dismiss="modal">关闭
                </button>
                <button type="button" class="btn btn-primary">
                    提交更改
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>
<script>
    console.log('test');
    var websocket = null;
    alert('欢迎来到wclist!');
    if ('WebSocket' in window) {
        websocket = new WebSocket('ws://bread.s1.natapp.cc/sell/webSocket')
    } else {
        alert('该浏览器不支持!');
    }

    websocket.onopen = function (event) {
        console.log('建立连接');
    };

    websocket.onclose = function (event) {
        console.log('关闭连接');
    };

    websocket.onmessage = function (event) {
        console.log('收到消息:' + event.data);
        //弹窗提醒,播放音乐
        $('#myModal').modal('show');
    };

    websocket.onerror = function (event) {
        alert('websocked通信发生错误');
    };

    window.onbeforeunload = function (event) {
        websocket.close();
    }

</script>
</body>
</html>

